package com.springboot.demo.design.pattern.operator.impl;

import com.springboot.db.entity.User;
import com.springboot.demo.design.pattern.enums.FormEnum;
import com.springboot.demo.design.pattern.form.Form;
import com.springboot.demo.design.pattern.instruction.user.UserSaveInstruction;
import com.springboot.demo.design.pattern.operator.Practicer;
import com.springboot.demo.design.pattern.request.user.UserSaveParam;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

/**
 * 保存用户实践者
 *
 * @author supu
 * @date 2019-03-19 16:13
 **/
@Component
public class UserSavePracticer extends BasePracticer implements Practicer<User, UserSaveParam>, InitializingBean {

    @Override
    public void operate(Form<User, UserSaveParam> form) {
        processorProxyFactory.getUserProcessor().saveUser(new UserSaveInstruction(form, userDao));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        dispatcher.register(FormEnum.USER_SAVE, this);
    }
}
